<%--
  Created by IntelliJ IDEA.
  User: sofwin
  Date: 2021/7/12
  Time: 11:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%String path = request.getContextPath() + "/";%>
<!doctype html>
<html>
<head>
    <base href="<%=path%>">
    <title>用户列表</title>
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
   <%@include file="/header.jsp"%>
</head>
<style>
</style>
<body style="background-color: #f3f3f4">
<div class="container" style="width: 100%;">
    <div class="row" style="height:680px;" id="container">
        <div class="col-md-2" id="left"
             style="margin-top:10px;height:100%;background-color: #ffffff;box-shadow: 1px 1px 3px rgba(0,0,0,.2);padding:10px 10px;border-radius: 10px;line-height: 50px;">

            <div class="panel panel-default">
                <div class="panel-heading" style="padding-top:0px;height: 60px;line-height: 60px">
                    组织机构
                    <i class="fa fa-search"></i>
                    <i class="fa fa-search"></i>
                    <i class="fa fa-search"></i>
                </div>
                <div class="panel-body">
                    <div class="ztree" id="tree"></div>
                </div>
            </div>

        </div>
        <div class="col-md-10" id="right">
            <div class="row"
                 style="background-color: #ffffff;box-shadow: 1px 1px 3px rgba(0,0,0,.2);margin: 10px 10px;padding:10px 10px;border-radius: 10px;line-height: 50px;">
                <form class="form-inline">
                    <input type="hidden" id="deptId" name="deptId"/>
                    <div class="form-group">
                        <label >登录名</label>
                        <input  type="text" class="form-control" name="loginAccount" id="loginAccount" placeholder="">
                    </div>
                    <div class="form-group">
                        <label >手机号</label>
                        <input  type="text" class="form-control" name="mobile" id="mobile" placeholder="">
                    </div>
                        <div class="form-group">
                        <label >用户状态</label>
                        <select class="form-control" name="status" id="status" >
                            <option value="-1">--全部--</option>
                            <option value="1">启用</option>
                            <option value="0">禁用</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>创建时间</label>
                        <input type="text" id="beginDate" class="form-control" placeholder="">
                        <input type="text" id="endDate" class="form-control" placeholder="">
                    </div>
                    <button type="button" class="btn btn-primary query">
                        <i class="fa fa-search"></i> 搜索
                    </button>
                    <button type="reset" class="btn btn-warning">
                        <i class="fa fa-refresh"></i>
                        重置
                    </button>
                </form>
            </div>
            <div class="row"
                 style="background-color: #ffffff;box-shadow: 1px 1px 3px rgba(0,0,0,.2);margin: 10px 10px;padding:10px 10px;border-radius: 10px;">
                <div id="toolbar">
                    <button class="btn btn-primary" id="add">
                        <i class="fa fa-plus" aria-hidden="true">&nbsp;</i>新增
                    </button>
                    <button id="edit" class="btn btn-success">
                        <i class="fa fa-pencil fa-fw"> &nbsp;</i>编辑
                    </button>
                    <button id="remove" class="btn btn-danger">
                        <i class="fa fa-trash-o fa-fw"> &nbsp;</i>删除
                    </button>
                </div>
                <table id="userData"></table>
            </div>
        </div>
    </div>
</div>

</body>
<script>
    var ztreeObject;
    var setting = {
         data:{
             simpleData:{
                 enable:true
             }
         },
        callback:{
         onClick:function(evn,treeId,node,flag){
             $("#deptId").val(node.id);
             _table.bootstrapTable('refresh');
         }
        }
    };

    function edit(id) {
        $.modal.openFull("编辑用户信息", "view/user/edit?sysId=" + id);
    }

    function deleteUser(id){
        layer.confirm('确认删除吗？', {icon: 3, title:'提示'}, function(index){
            $.ajax({
                url:'user/delete?id='+id,
                type:'get',
                dataType:'json',
                success:function(ret){
                    if(ret.status){
                        layer.msg(ret.msg,function(){
                            a();
                        })
                    }else{
                        layer.msg(ret.msg);
                    }
                }

            });
        });

    }
    $(function () {

        $("#remove").click(function(){
            // 所有多选选中的行
            let $rows = _table.bootstrapTable("getSelections");
            if($rows.length==0){
                layer.msg('请选择需要删除的数据');
                return;
            }
            // 将js数组封装为集合或数组
            let array = new Array();
            for(let i=0;i<$rows.length;i++){
                array.push($rows[i].sysId);
            }
            $.modal.deletes('user/deletes',{ids:array});
        });


        $("#add").click(function () {
            $.modal.openFull("新增用户信息", "view/user/edit");
        })

            $.modal.post("dept/treeData","",function (ret) {
                if(ret.code==200){
                    ztreeObject = $.fn.zTree.init($("#tree"), setting, ret.data);
                }
            });
        $(".query").click(function () {
            _table.bootstrapTable('refresh')
        });

        // 初始化表格
        function initTable() {
            let columns=[{
                checkbox:true
            },{
                field: 'sysId',
                sortable: true,
                title: '用户ID'
            }, {
                field: 'loginAccount',
                sortable: true,
                title: '用户登录名'
            }, {
                field: 'realName',
                sortable: true,
                title: '姓名'
            },  {
                field: 'status',
                sortable: true,
                title: '状态',
                formatter:function(value,row,index){
                    if(value==1){
                        return "启用";
                    }else{
                        return "禁用";
                    }

                }
            },{
                field: 'createDate',
                sortable: true,
                title: '创建时间'
            },
                {
                    title: '操作',
                    width: '150px',
                    align: 'center',
                    formatter: function (value, row, index) {
                        // 当前行的数据
                        // 当前循环的次数
                        return '<a href="javascript:void(0)" onclick="edit(' + row.sysId + ')" class="edit" title="编辑用户"><i class="fa fa-pencil"></i></a>&nbsp;&nbsp;<a href="javascript:void(0)" onclick="deleteUser('+row.sysId+')" title="删除用户"><i class="fa fa-trash-o"></i></a>';
                    }
                }];
            $.modal.initTable($("#userData"),columns,'user/data');
        }

        initTable();

    })

</script>
</html>
